<?php

class BannerTable extends Doctrine_Table {

    public function findStructureBanners($structID, $type = false) {

        $query = Doctrine_Query::create()
                ->select('b.name, b.id, b.file, b.link, bg.id as group')
                ->from('Banner b')
                ->innerJoin('b.BannerGroup bg')
                ->innerJoin("bg.StructureBannerGroups bgvs WITH bgvs.structure_id = '$structID'")
                ->groupBy('bg.id, b.id');
        if (isset($param)) {
            $query->andWhere('bg.type = ?', $type);
        }
        $queryResult = $query->execute();

        $result = array();

        foreach ($queryResult as $banner) {
            $result[$banner->group][] = $banner;
        }

        return $result;
    }

    public function getAssociatedToCategoryBannersQuery($catID) {

        return $this->createQuery('category_banners')
                ->from('Banner b')
                ->innerJoin('b.BannerGroup bg WITH bg.id = ?', $catID);
    }

}